/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Login;

import java.awt.event.KeyEvent;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

/**
 *
 * @author Yosefina
 */
public class LoginController {

    public static void openLoginForm() {
        new LoginForm().setVisible(true);
    }

    public void login(Karyawan karyawan, javax.swing.JFrame frame) throws SQLException, IOException, Exception {
        String passCek = Karyawan.getKoneksiKontrol().login(karyawan);
        if (passCek.equals(karyawan.getPassword())) {
            Karyawan.setUserID(karyawan);
            Karyawan.setStatusLogin(1);
            frame.setVisible(false);

           LoginForm loginForm=(LoginForm) frame;
           
            new MainForm(loginForm.waktuLogin).setVisible(true);
        } else {
            throw new Exception(passCek);
        }
    }

    public static void showKaryawan(JLabel nama, JLabel idKaryawan, JLabel jabatan)
            throws FileNotFoundException, IOException, SQLException, Exception {
        List<Karyawan> kTest = Karyawan.getKoneksiKontrol().getDataKaryawan(Karyawan.getusrID());
        for (Karyawan k : kTest) {
            nama.setText(k.getLastName() + ", " + k.getFirstName());
            idKaryawan.setText(k.getUsername());
            jabatan.setText(k.getJabatan());
        }
    }

    public static void aturMenuKaryawan(JFrame frame, JLabel label, JMenuItem JMI1, JMenuItem JMI2, JMenuItem JMI3, JMenuItem JMI4,  JPanel panel, JButton button) {
        if (label.getText().toUpperCase().matches("ADMINISTRASI")) {
            JMI1.setVisible(true);
            JMI2.setVisible(true);
            JMI3.setVisible(false);
            JMI4.setVisible(false);
            
            panel.setBorder(javax.swing.BorderFactory.createTitledBorder(
                    null, "Admin Page",
                    javax.swing.border.TitledBorder.LEFT,
                    javax.swing.border.TitledBorder.DEFAULT_POSITION,
                    new java.awt.Font("Tahoma", 0, 14)));
            button.setVisible(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        } else {
            JMI1.setVisible(false);
            JMI2.setVisible(false);
            JMI3.setVisible(true);
            JMI4.setVisible(true);
            MainForm mainForm=(MainForm) frame;
            mainForm.exitMenuItem.setVisible(false);
            
            panel.setBorder(javax.swing.BorderFactory.createTitledBorder(
                    null, "Staff Parkir Page",
                    javax.swing.border.TitledBorder.LEFT,
                    javax.swing.border.TitledBorder.DEFAULT_POSITION,
                    new java.awt.Font("Tahoma", 0, 14)));
            button.setVisible(false);
            frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
        }
    }

    public static void showHelp(){
        try {
            Process pr = Runtime.getRuntime().exec("cmd /c start rplt.chm");
        } catch (IOException ex) {
        }
    }
}
